import time

import schedule
import win32gui
from pynput import keyboard
from utils.wuseng1 import Diablo


pause = False
window_title = "暗黑破坏神III"  # 替换为目标窗口标题
hwnd = win32gui.FindWindow(None, window_title)
if not hwnd:
    print("暗黑破坏神III未运行！")
    input()
    exit(1)

diablo = Diablo(hwnd)

def on_press(key):
    try:
        print(f'字母键 {key.char} 被按下')

    except AttributeError:

        if str(key) == "Key.space":
            print("开始或暂停 ")
            global pause
            pause = not pause
            if pause:
                diablo.ButtonRightDown()
            else:
                diablo.ButtonRightUp()



        print(f'特殊键 {key} 被按下')


def on_release(key):
    print(f'{key} 被释放')



if __name__ == "__main__":


    # 监听键盘事件
    listener=keyboard.Listener(
            on_press=on_press,
            on_release=on_release,
    daemon=True)
    listener.start()



    schedule.every(4).seconds.do(diablo.one)
    schedule.every(3).seconds.do(diablo.two)
    schedule.every(6).seconds.do(diablo.three)
    schedule.every(15).seconds.do(diablo.four)
    schedule.every(30).seconds.do(diablo.Q)





    while True:
        if pause:
            schedule.run_pending()
        time.sleep(1)

    input()